package org.grizz.game;

import org.grizz.game.input.ScreenSwitcherInputProcessor;
import org.grizz.game.view.ScreenTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.FPSLogger;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;

@Configurable
public class GameTemplate extends Game {
	
	@Autowired
	private TestService service;
	
	@Autowired
	private InputProcessor inputProcessor;
	
	private FPSLogger fpsLogger;

	ScreenTemplate screen;
	
	@Override
	public void create() {
		fpsLogger = new FPSLogger();
		Gdx.input.setInputProcessor(inputProcessor);
		ScreenSwitcherInputProcessor processor = new ScreenSwitcherInputProcessor(this);
		InputMultiplexer multiplexer = (InputMultiplexer) inputProcessor;
		multiplexer.addProcessor(processor);
		
		screen = new ScreenTemplate();
		processor.addScreen(screen);
		
		processor.addScreen(new Screen() {
			
			@Override
			public void show() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void resume() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void resize(int width, int height) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void render(float delta) {
				// TODO Auto-generated method stub

				GLCommon gl = Gdx.gl;
		        gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
			}
			
			@Override
			public void pause() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void hide() {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void dispose() {
				// TODO Auto-generated method stub
				
			}
		});
		
		this.setScreen(screen);
		
		service.run();
	}
	
	@Override
	public void render() {
		super.render();
		
		fpsLogger.log();
	}

}
